<template>
  <div class="app-container">
    <el-table
      lazy
      :load="loadData"
      v-if="refreshTable"
      v-loading="loading"
      :data="areaList"
      row-key="id"
      :default-expand-all="isExpandAll"
      :tree-props="{children: 'children', hasChildren: 'hasChildren' }">
      <el-table-column prop="cityName" label="城市名称" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column prop="id" label="城市编码" ></el-table-column>
      <el-table-column prop="mergerName" label="城市位名" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column prop="chn" label="英文名" :show-overflow-tooltip="true" ></el-table-column>
    </el-table>
  </div>
</template>

<script>
import { listArea } from '@/api/system/area'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "area",
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 菜单表格树数据
      areaList: [],
      // 菜单树选项
      menuOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展开，默认全部折叠
      isExpandAll: false,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        cityName: undefined,
        cityCode: undefined,
        parentId: 0
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询菜单列表 */
    getList() {
      this.loading = true;
      listArea(this.queryParams).then(response => {
        this.areaList = response.data
        this.loading = false;
      });
    },
    loadData(tree, treeNode, resolve) {
      this.queryParams.parentId = tree.id
      listArea(this.queryParams).then(response => {
        resolve(response.data);
        this.loading = false;
      });
      this.loading = false
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        menuId: undefined,
        parentId: 0,
        menuName: undefined,
        icon: undefined,
        menuType: "M",
        orderNum: undefined,
        isFrame: "1",
        isCache: "0",
        visible: "0",
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
